#include<iostream>
#include<pthread.h>
#include<unistd.h>
using namespace std;
pthread_mutex_t gmutes =PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t gcond =PTHREAD_COND_INITIALIZER;
void * Wait(void * args)
{
    std::string name=static_cast<const char*>(args);
    while (true)
    {
        /* code */
        pthread_mutex_lock(&gmutes);
        pthread_cond_wait(&gcond,&gmutes);
        std::cout<<"I am :"<<name<<std::endl;
        pthread_mutex_unlock(&gmutes);
        usleep(100000);
    }
    
}
int main ()
{
    pthread_t threads[4];
    for(int i=0;i<4;i++)
    {
        char* name=new char[1024];
        snprintf(name,1024,"thread_%d",i+1);
        pthread_create(threads+i,nullptr,Wait,(void*)name);
    }
    while(true)
    {
        //pthread_cond_signal(&gcond);
        pthread_cond_broadcast(&gcond);
        std::cout<<"唤醒的一个线程"<<std::endl;
        sleep(2);
    }
    for ( int i=0;i<4 ;i++)
    {
        pthread_join(threads[i],nullptr);
    }

    return 0;
}